// camera.h
#ifndef CAMERA_H
#define CAMERA_H
 
#include <initializer_list>
#include <libobsensor/hpp/Frame.hpp>
#include <libobsensor/hpp/Pipeline.hpp>
#include <libobsensor/hpp/Types.hpp>
#include <opencv2/core.hpp>

// 新增
#include <map>
#define ESC 27

class Camera {
  private:
    std::shared_ptr<ob::Device> device;
    std::shared_ptr<ob::Pipeline> pipe;
    std::shared_ptr<ob::Config> config;
    void init_color();
    void init_IR();
    void init_depth();

    // 新增
    int16_t init_depth_precision();

    // 新增
    std::map<OBDepthPrecisionLevel, std::string> depthUnitMap;
    std::vector<uint16_t> precisionList;
    OBDepthPrecisionLevel curDepthPrecisionlevel;
    float                 unit;
 
  public:
    Camera(bool color, bool IR, bool depth);
    inline ~Camera() { this->pipe->stop(); }
    inline void start() { this->pipe->start(this->config); }
    inline void stop() { this->pipe->stop(); }
    inline std::shared_ptr<ob::FrameSet> get() { return pipe ? pipe->waitForFrames(100) : nullptr; }
    static cv::Mat frame2mat(const std::shared_ptr<ob::VideoFrame> &frame);

    // 新增
    static void pressKeyExit(std::string msg);
    void depthPrecisionConversion(std::shared_ptr<ob::DepthFrame> depthFrame);
    uint16_t get_depth(std::shared_ptr<ob::DepthFrame> &depthFrame, std::vector<cv::Point2f> centers);
};
 
#endif